package com.epoint.mobileoa.tools;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;

import com.epoint.mobileoa.ui.init.InitView;

import android.content.Context;
import android.util.Log;

/**
 * @author liyc
 * @time 2012-1-9 上午11:19:48
 * @annotation 日志帮助类
 */
public class LogHelp {
	
	
//
//
	public static void LogI(String msg){
		Log.i("MobileOA", msg);
	}

	public static void LogTag(Context con,String msg){
		Log.i(con.getClass().getSimpleName(), msg);
	}

	public static void LogE(String msg){
		Log.e("MobileOA", msg);
	}

	/**
	 * 将日志写入到SD卡
	 */
	public static void Log2SDInfo(String log){
		String LogPath = "/"+InitView.MobileOaMainStoreFolder+"/mobileoa/log";
		try{
			String logName = DateHelp.convertDate(new Date(), "yyyy-MM-dd")+".log";
			File file = new File(LogPath);
			if(!file.exists()){
				file.mkdirs();
			}
			PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(LogPath+"/"+logName, true)));
			pw.write("<EpointLog>");
			String dataTag = "<time>"+DateHelp.convertDate(new Date(), DateHelp.DateFormat_24)+"</time>";
			pw.write(dataTag);
			pw.write(log);
			pw.write("</EpointLog>");
			pw.write("\r\n");
			pw.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
//
//	/**
//	 * 将错误日志写入到SD卡
//	 */
//	public static void Log2SDErr(Exception e){
//		String LogPath = "/"+InitView.MobileOaMainStoreFolder+"/mobileoa/log";
//		try{
//			StringWriter sw = new StringWriter();
//			e.printStackTrace(new PrintWriter(sw, true));
//			String msg = sw.toString();
//			LogE(msg);
//			String logName = DateHelp.convertDate(new Date(), "yyyy-MM-dd")+".log";
//			File file = new File(LogPath);
//			if(!file.exists()){
//				file.mkdirs();
//			}
//			PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(LogPath+"/"+logName, true)));
//			pw.write("[MobileOA-ERROR]");
//			String dataTag = "["+DateHelp.convertDate(new Date(), "HH:mm:ss")+"]";
//			pw.write(dataTag);
//			pw.write(msg);
//			pw.write("\r\n");
//			pw.close();
//		}catch(Exception e2){
//			e2.printStackTrace();
//		}
//	}
//
//
}
